package com.isoft.service;

import com.isoft.entity.FixRecord;
import com.isoft.mapper.FixRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class FixRecordService {
    @Autowired
    private FixRecordMapper fixRecordMapper;
    public void userFixRecord(FixRecord fixRecord){
        fixRecordMapper.insert(fixRecord);
    }

    public List<FixRecord> queryFixRecords(String startDateStr, String endDateStr) {
        try {
            // 定义日期格式
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            // 将字符串转换为LocalDateTime
            LocalDateTime startDate = LocalDateTime.parse(startDateStr, formatter);
            LocalDateTime endDate = LocalDateTime.parse(endDateStr, formatter);
            // 调用查询方法
            return fixRecordMapper.queryByDateRange(startDate, endDate);
        } catch (Exception e) {
            // 日期转换失败或查询过程中出现异常时的处理
            e.printStackTrace();
            // 根据你的业务需求返回空列表或者抛出异常
            return null; // 或者 throw new RuntimeException("日期转换失败或查询异常", e);
        }
    }

}

